package com.yurun.service.impl;

import com.yurun.entity.ScheduleJob;
import com.yurun.exception.PersistenceException;
import com.yurun.mapper.ScheduleJobMapper;
import com.yurun.service.ScheduleJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScheduleJobServiceImpl implements ScheduleJobService {
    @Autowired
    ScheduleJobMapper scheduleJobMapper;

    @Override
    public void addJob(ScheduleJob scheduleJob){
        if(scheduleJobMapper.addJob(scheduleJob)!=1){
            throw new PersistenceException("添加任务失败");
        }
    }

    @Override
    public void deleteJobById(Long id){
        if(scheduleJobMapper.deleteJobById(id)!=1){
            throw new PersistenceException("删除任务失败");
        }
    }

    @Override
    public void updateJob(ScheduleJob scheduleJob){
        if(scheduleJobMapper.updateJob(scheduleJob)!=1){
            throw new PersistenceException("更新任务失败");
        }
    }

    @Override
    public void updateJobStatusById(Long id,Boolean status){
        if(scheduleJobMapper.updateJobStatusById(id, status)!=1){
            throw new PersistenceException("更新任务状态失败");
        }
    }

    @Override
    public List<ScheduleJob> getJobList(){
        return scheduleJobMapper.getJobList();
    }

    @Override
    public ScheduleJob getJobById(Long id){
        return scheduleJobMapper.getJobById(id);
    }
}
